package thn.glf.org.personalfinancial;

import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;

import thn.glf.org.personalfinancial.model.FinancialDayAdapter;
import thn.glf.org.personalfinancial.objData.FinancialDay;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.ExpandableListView;
import android.widget.TextView;

public class MoneyOfDayListActivity extends Activity {
private ExpandableListView lv;
String day;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.moneyofdaylist);
		this.lv=(ExpandableListView)findViewById(R.id.lstday);
		setday();
		FinancialDay lst=new FinancialDay();
		lst.setmContext(this);
		lv.setAdapter(new FinancialDayAdapter(this, lst.getListInDay(day)));
		TextView total=(TextView)findViewById(R.id.total);
		 DecimalFormat df = new DecimalFormat();
		total.setText("Tổng Chi:"+df.format(lst.TotalMoneyuse(day))+"VNĐ");
	}
public void setday(){
	Intent i = getIntent();
	Bundle bundle = i.getBundleExtra("listday");
	if (bundle != null) {
		day=bundle.getString("day");
	}else{
		Calendar currentDate = Calendar.getInstance();
		SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMdd");
		String currentdatetime = formatter.format(currentDate.getTime());
		day=currentdatetime;
	}
}
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.money_of_day_list, menu);
		return true;
	}
	public boolean onOptionsItemSelected(MenuItem item) {
		switch (item.getItemId()) {
		case R.id.mnAdd: {
			Intent intent = new Intent();
			intent.setClass(this, MoneyOfDayActivity.class);
			this.startActivity(intent);
		}
		
		}
		return true;

	}
	protected void onResume() {
		super.onResume();
		setday();
		FinancialDay lst=new FinancialDay();
		lst.setmContext(this);
		lv.setAdapter(new FinancialDayAdapter(this, lst.getListInDay(day)));
		TextView total=(TextView)findViewById(R.id.total);
		 DecimalFormat df = new DecimalFormat();
		total.setText("Tổng Chi:"+df.format(lst.TotalMoneyuse(day))+"VNĐ");
}
}